<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";

// -----------------------------------------------------------------------------
// 访问设置
// -----------------------------------------------------------------------------

if (!isset($_GET['order'])) {
    exit("需要传入有效的参数！");
}

$order = $_GET['order'];

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath; // 不加这行语句的话会报错，提示找不到对应路径
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------

$links = $db->getListOfLinks($order);

// -----------------------------------------------------------------------------
// 页内导航动态标题
// -----------------------------------------------------------------------------

$titles = [
    "timeCreate" => "最近添加",
    "timeLastEdit" => "最近编辑",
    "timeLastMove" => "最近移动",
    "timeLastClick" => "最近点击",
];

if (array_key_exists($order, $titles)) {
    $title = $titles[$order];
} else {
    $title = "最近";
}

// -----------------------------------------------------------------------------
?>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>最近</title>
    <base target="_self">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="../resources/bootstrap-5.2.0-beta1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../global.css">
</head>
<body>

<!-- ----------------------------------------------------------------------- -->

<script src="../resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>
<script src="../resources/jQuery/jquery-3.5.1.js"></script>
<?php include "../globalNavbar.php"; ?>

<!-- ----------------------------------------------------------------------- -->

<!--div:container start-->
<div class="mainContainer container container-fluid mb-5">

    <!-- 导航栏 开始 -->
    <div class="mt-3">
        <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item mt-0"><a class="text-decoration-none" href="<?php echo $homepage; ?>">首页</a></li>
                <li class="breadcrumb-item mt-0 active"><?php echo $title; ?></li>
            </ol>
        </nav>
    </div>
    <!-- 导航栏 结束 -->

    <div id="content" class="mt-3">

        <?php

        if (count($links) == 0) {
            echo <<<BBB
                <div class="alert alert-info" role="alert">
                    <p class="mb-0">暂时没有相关的数据。</p>
                </div>
            BBB;
        } else {
            echo <<<BBB
                <div class="list-group mt-3">
            BBB;

            foreach ($links as $link) {
                extract($link);
                $url = "../category/linksInCategory.php?categoryId={$categoryId}&linkId={$id}";
                echo <<<BBB
                    <a href="$url" class="list-group-item list-group-item-action d-flex" target="_self">
                       <span class="w-100 text-break">$title</span>
                       <span class="flex-shrink-0">
                           <span class="badge rounded-pill text-bg-light">{$timesOfClick}点击</span>
                       </span>
                    </a>
                BBB;
            }

            echo <<<BBB
                </div>
            BBB;
        }

        ?>

    </div>

</div>
<!--div:container end-->

<!-- ----------------------------------------------------------------------- -->

<!-- 添加「返回顶部按钮」 -->
<script src="../resources/vanilla-back-to-top/index.js"></script>
<script src="../resources/vanilla-back-to-top/config.js"></script>

<!-- ----------------------------------------------------------------------- -->

</body>
</html>
